#include "cpu/exec.h"


make_EHelper(mul) {
    rtl_mul_lo(&id_dest->val, &id_src->val, &id_src2->val);
    rtl_sr(id_dest->reg, &id_dest->val, 4);
    print_asm_template4(mul);
}


make_EHelper(mulh) {
    rtl_imul_hi(&id_dest->val, &id_src->val, &id_src2->val);
    rtl_sr(id_dest->reg, &id_dest->val, 4);
    print_asm_template4(mulh);    
}

make_EHelper(mulhsu) {
    // id_dest->val = (((int64_t)(int32_t)(id_src->val) * (uint64_t)(id_src2->val)) >> 32);
    rtl_mul_hisu(&id_dest->val, &id_src->val, &id_src2->val);
    rtl_sr(id_dest->reg, &id_dest->val, 4);
    print_asm_template4(mulhsu);      
}

make_EHelper(mulhu) {
    rtl_mul_hi(&id_dest->val, &id_src->val, &id_src2->val);
    rtl_sr(id_dest->reg, &id_dest->val, 4);
    print_asm_template4(mulhu);        
}

make_EHelper(div) {
    rtl_idiv_q(&id_dest->val, &id_src->val, &id_src2->val);
    rtl_sr(id_dest->reg, &id_dest->val, 4);
    print_asm_template4(div);       
}

make_EHelper(divu) {
    rtl_div_q(&id_dest->val, &id_src->val, &id_src2->val);
    rtl_sr(id_dest->reg, &id_dest->val, 4);
    print_asm_template4(divu);    
}

make_EHelper(rem) {
    rtl_idiv_r(&id_dest->val, &id_src->val, &id_src2->val);
    rtl_sr(id_dest->reg, &id_dest->val, 4);
    print_asm_template4(rem);        
}

make_EHelper(remu) {
    rtl_div_r(&id_dest->val, &id_src->val, &id_src2->val);
    rtl_sr(id_dest->reg, &id_dest->val, 4);
    print_asm_template4(remu);    
}

